package com.lowrisk.springcloud;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Date;

/**
 * @Author jiadianduo
 * @Description:
 * @Date:Created in 2019/3/24 23:38
 */
@RestController
public class UserController {

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/findOrderByUser/{id}")
    @HystrixCommand(fallbackMethod = "fallbackInfo")
    public String findOrderByUser(@PathVariable String id) {
        return this.restTemplate.getForObject("http://microservice-eureka-order/order/" + id+"?time="+new Date().getTime(), String.class);
    }

    public String fallbackInfo(@PathVariable String id){
        return "服务不可用，请稍后再试"+id;
    }

}
